package com.wangsb.controller;

import com.wangsb.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: TODO
 * @author: shenbing.wang@hand-china
 * @date: 2021年02月21日 23:07
 */
@RestController
@RequestMapping("/json")
public class JsonController {


    @GetMapping("/response")
    @ResponseBody
    public User responseJson() {
        User user = new User(1, "wangsb", "123456", new Date());
        return user;
    }

    @GetMapping("/response2")
    @ResponseBody
    public String responseJson2() {
        return "212121";
    }

    @PostMapping("/request01")
    @ResponseBody
    public User request01(@RequestBody String name) {
        System.out.println("name = " + name);
        return new User(3, "呼啦啦", "122121", new Date());
    }



    @PostMapping("/request02")
    @ResponseBody
    public User request02(@RequestBody Map<String, Object> map) {
        System.out.println("map = " + map);
        return new User(3, "呼啦啦", "122121", new Date());
    }

    @PostMapping("/request03")
    @ResponseBody
    public User request03(@RequestBody List<User> list) {
        System.out.println("list = " + list);
        return new User(3, "呼啦啦", "122121", new Date());
    }
    @GetMapping("/response3")
    @ResponseBody
    public List<User> responseJson3() {
        User user = new User(1, "wangsb", "123456", new Date());
        User user2 = new User(2, "wangsb2222222", "123456", new Date());
        List<User> list = new ArrayList<>();
        list.add(user2);
        list.add(user);
        return list;
    }
}
